package Service;

import Entity.Admin;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import dao.AdminDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminDao, Admin> implements AdminService {

    @Autowired
    private AdminDao adminDao;

    @Override
    public Boolean modifyOwnInfo ( Admin admin ) {
        return adminDao.updateById ( admin ) > 0;
    }

    @Override
    public Admin getAdminById ( Integer id ) {
        return adminDao.selectById ( id );
    }

    @Override
    public List<Admin> getAllAdmin ( ) {
        return adminDao.selectList ( null );
    }

    @Override
    public Boolean updateAdminInfo ( Admin admin ) {
        return adminDao.updateById ( admin ) > 0;
    }

    @Override
    public Boolean saveAdmin ( Admin admin ) {
        return adminDao.insert ( admin ) > 0;
    }

    @Override
    public Boolean deleteAdminById ( Integer id ) {
        return adminDao.deleteById ( id ) > 0;
    }

    @Override
    public Admin login ( Integer id , String password ) {
        Admin currentAdmin = adminDao.selectById ( id );
        if (currentAdmin != null) {
            if (currentAdmin.getPassword ().equals ( password )) {
                System.out.println ( "登陆成功！" );
                return currentAdmin;
            } else {
                System.out.println ( "密码输入错误,登陆失败！" );
                return null;
            }
        } else {
            System.out.println ( "无此ID号，是否注册?" );
            return null;
        }
    }
}
